<template>
	<view class="header-banner" @click="bindShare">
		<image src="../../static/fuj.png" class="pic" mode=""></image>
		<view class="content">
			<view class="">
				<text>邀友得好礼</text>
				<image src="../../static/code.png" mode=""></image>
			</view>
			<text>邀请好友越多，赚的服务金越多</text>
			<button class="btn">立即邀请</button>
		</view>
	</view>
	<view class="box">
		<view class="box-header">
			<image src="../../static/fuj-1.png" mode=""></image>
			<text>我的奖励</text>
			<image src="../../static/fuj-2.png" mode=""></image>
		</view>
		<view class="content">
			<view class="content-item">
				<text class="value">{{data.allAmount/100}}</text>
				<text class="label">累计奖励</text>
			</view>
			<view class="content-item">
				<text class="value">{{data.balance/100}}</text>
				<text class="label">可提现</text>
			</view>
			<view class="content-item" style="border: none;">
				<text class="value">{{data.preAmount/100}}</text>
				<text class="label">待入账</text>
			</view>
		</view>
		<button class="btn" @click="bindWithdrawal">提现</button>
	</view>
	<view class="box">
		<view class="box-header">
			<image src="../../static/fuj-1.png" mode=""></image>
			<text>好友奖励结果</text>
			<image src="../../static/fuj-2.png" mode=""></image>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in data.shareList" :key="index">
				<view class="">
					<image src="/static/logo.png" mode=""></image>
					<text>{{item.memberName}}</text>
				</view>
				<text>已完成</text>
			</view>
			<uni-empty v-if="emptyState"></uni-empty>
		</view>
	</view>
</template>

<script setup>
	import {
		shareInfo,
		withdraw
	} from '@/api'
	import {
		wxOpenid,

	} from '@/utils/login-sdk.js'
	import {
		ref
	} from 'vue';
	const data = ref({
		allAmount:0,
		balance:0,
		preAmount:0,
		shareList:[]
	})
	const emptyState = ref(false)
	import {
		onLoad,

	} from '@dcloudio/uni-app'
	onLoad(() => {
		getData()
	})
	const getData = async () => {
		const {
			memberId
		} = await wxOpenid()
		const res = await shareInfo({
			memberId
		})
		data.value = res.result
		if(res.result.shareList.length){
			emptyState.value = false
		}else{
			emptyState.value = true
		}
	}
	/** 分享 */
	const bindShare = () => {
		uni.navigateTo({
			url: "/pages/share/share"
		})
	}
	/** 提现 */
	const bindWithdrawal = ()=>{
		if(data.value.balance<=0){
			uni.showModal({
				title:'提示',
				content:'没有可提现金额',
			})
			return false
		}
		uni.showModal({
			title:'提示',
			content:'是否全部提现',
			success: async(ret) => {
				if(ret.confirm){
					const res = await withdraw()
				}
			}
		})
	}
</script>

<style lang="scss">
	page {
		background: #F8F5F0;
		padding-bottom: constant(safe-area-inset-bottom);
		/*兼容 IOS<11.2*/
		padding-bottom: env(safe-area-inset-bottom);
		/*兼容 IOS>11.2*/
	}

	.header-banner {
		width: 702rpx;
		height: 272rpx;
		position: relative;
		margin: 28rpx auto;

		.pic {
			width: 702rpx;
			height: 272rpx;
			position: absolute;
			top: 0;
			left: 0;
			border-radius: 36rpx;
		}

		.content {
			width: 702rpx;
			height: 272rpx;
			position: absolute;
			top: 0;
			left: 0;

			>view {
				display: flex;
				align-items: center;
				// margin-bottom:20rpx;
				margin-top: 53rpx;
				margin-left: 50rpx;

				text {
					font-weight: bold;
					font-size: 34rpx;
					color: #FFFFFF;
					margin-right: 19rpx;
				}

				image {
					width: 34rpx;
					height: 34rpx;
				}
			}

			>text {
				font-size: 26rpx;
				color: #FFFFFF;
				margin-left: 50rpx;
			}

			.btn {
				width: 160rpx;
				height: 70rpx;
				background: #FFFFFF;
				border-radius: 35rpx;
				margin-left: 50rpx;
				margin-top: 27rpx;
				display: block;
				font-size: 26rpx;
				color: #FF5330;
				line-height: 70rpx;
			}
		}
	}

	.box {
		width: 630rpx;
		padding: 36rpx;
		background: #FFFFFF;
		border-radius: 36rpx;
		margin: 20rpx auto;

		.box-header {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom: 43rpx;

			image {
				width: 20rpx;
				height: 29rpx;
				display: block;
			}

			text {
				font-weight: bold;
				font-size: 34rpx;
				color: #16191B;
				margin: 0 20rpx;
			}
		}

		.content {
			width: 646rpx;
			height: 195rpx;
			background: #F7F7F7;
			border-radius: 36rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			.content-item {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				border-right: 2rpx solid #DCDCDC;
				height: 100rpx;
				width: 197rpx;

				.value {
					font-weight: bold;
					font-size: 46rpx;
					color: #16191B;

					&::after {
						content: "元";
						font-weight: bold;
						font-size: 21rpx;
						color: #16191B;
					}
				}

				.label {
					font-size: 26rpx;
					color: #16191B;
				}
			}

		}

		.btn {
			width: 640rpx;
			height: 100rpx;
			background: linear-gradient(90deg, #FFC53D 0%, #FE9B23 51%, #FFC53D 100%);
			box-shadow: 4rpx 12rpx 18rpx 0rpx rgba(254, 155, 35, 0.25);
			border-radius: 28rpx;
			font-weight: bold;
			font-size: 34rpx;
			color: #FFFFFF;
			line-height: 100rpx;
			display: block;
			margin-top: 37rpx;
		}

		.list {
			.item {
				width: 646rpx;
				height: 110rpx;
				background: #F7F7F7;
				border-radius: 36rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 10rpx;

				view {
					display: flex;
					align-items: center;

					image {
						width: 60rpx;
						height: 60rpx;
						background: #FFD8A9;
						border-radius: 50%;
						display: block;
						margin-right: 18rpx;
						margin-left: 42rpx;
					}

					text {
						font-size: 28rpx;
						color: #16191B;
					}
				}

				>text {
					font-size: 28rpx;
					color: #16191B;
					margin-right: 45rpx;
				}
			}
		}

	}
</style>